package com.example.shop.adapter

import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.widget.LinearLayout
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.example.base.entity.CategoryEntity
import com.example.shop.R

class CateParentAdapter(list: MutableList<CategoryEntity>):BaseQuickAdapter<CategoryEntity,BaseViewHolder>(
    R.layout.item_cate_parent,list) {
    //默认值为1，因为咱们默认加载的是电脑办公，其中他的id就是1
    var selectedItemId = 1
    override fun convert(holder: BaseViewHolder, item: CategoryEntity) {
        holder.setText(R.id.cate_parent_tv,item.category_name)
        holder.getView<LinearLayout>(R.id.ll_parent).background = if(item.id==selectedItemId) ColorDrawable(Color.GREEN) else null
    }
    fun setSelectedItem(id:Int){
        selectedItemId = id
        notifyDataSetChanged()
    }
}